package com.zhouchb.test;

import java.util.HashMap;
import java.util.Map;

/**
 * @Create 2023-09-17 19:50
 * @Description
 */
public class 出现次数最多的数 {
    public static void main(String[] args) {
        int[] arr = {1,3,4,5,6,9,4,5,5,6,6};
        Map<Integer, Integer> countMap = new HashMap<>();
        for (int i = 0; i < arr.length; i++) {
            if (countMap.containsKey(arr[i])){
                countMap.put(arr[i],countMap.get(arr[i])+1);
            }else {
                countMap.put(arr[i],1);
            }
        }
        int maxCount=0,num=arr[0];
        for (Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
            if (entry.getValue()>maxCount){
                maxCount = entry.getValue();
                num = entry.getKey();
            }
        }
        System.out.println("出现次数最多的数是："+num+"，出现"+maxCount+"次");
    }
}
